package com.ruoyi.am.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.am.domain.AmVersion;
import com.ruoyi.am.service.IAmVersionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 安卓版本Controller
 * 
 * @author hkkk
 * @date 2021-01-06
 */
@Controller
@RequestMapping("/am/version")
public class AmVersionController extends BaseController
{
    private String prefix = "am/version";

    @Autowired
    private IAmVersionService amVersionService;

    @RequiresPermissions("am:version:view")
    @GetMapping()
    public String version()
    {
        return prefix + "/version";
    }

    /**
     * 查询安卓版本列表
     */
    @RequiresPermissions("am:version:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AmVersion amVersion)
    {
        startPage();
        List<AmVersion> list = amVersionService.selectAmVersionList(amVersion);
        return getDataTable(list);
    }

    /**
     * 导出安卓版本列表
     */
    @RequiresPermissions("am:version:export")
    @Log(title = "安卓版本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AmVersion amVersion)
    {
        List<AmVersion> list = amVersionService.selectAmVersionList(amVersion);
        ExcelUtil<AmVersion> util = new ExcelUtil<AmVersion>(AmVersion.class);
        return util.exportExcel(list, "version");
    }

    /**
     * 新增安卓版本
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存安卓版本
     */
    @RequiresPermissions("am:version:add")
    @Log(title = "安卓版本", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AmVersion amVersion)
    {
        return toAjax(amVersionService.insertAmVersion(amVersion));
    }

    /**
     * 修改安卓版本
     */
    @GetMapping("/edit/{versionId}")
    public String edit(@PathVariable("versionId") Long versionId, ModelMap mmap)
    {
        AmVersion amVersion = amVersionService.selectAmVersionById(versionId);
        mmap.put("amVersion", amVersion);
        return prefix + "/edit";
    }

    /**
     * 修改保存安卓版本
     */
    @RequiresPermissions("am:version:edit")
    @Log(title = "安卓版本", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AmVersion amVersion)
    {
        return toAjax(amVersionService.updateAmVersion(amVersion));
    }

    /**
     * 删除安卓版本
     */
    @RequiresPermissions("am:version:remove")
    @Log(title = "安卓版本", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(amVersionService.deleteAmVersionByIds(ids));
    }


    @GetMapping("/getNowVersion")
    @ResponseBody
    public AmVersion getNowVersion(){
        return amVersionService.selectAmVersionByStatus(1);
    }

}
